﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using LiuYan.Entity;
using LiuYan.Service;
using LiuYan.Web.Controllers;

namespace LiuYan.Web.Areas.Mall.Controllers
{
    public class GoodsController : BaseController
    {
        //
        // GET: /Mall/Goods/

        public ActionResult GoodList()
        {
            ViewData["goodsort"] = new SortService().GetList();
            ViewData["dgood"] = new GoodService().GetDiscountGoods(3);
            ViewData["rxgood"] = new GoodService().GetRxGood(100,0,"").Tables[1];
            return View();
        }

        public DataTable GetGoods(int sort)
        {
            return new GoodService().GetList(sort);
        }

        public ActionResult Goods(int id)
        {
            ViewData["sort"] = new SortService().GetSortName(id);
            ViewData["id"] = id;
            return View();
        }

        public ActionResult GoodSort()
        {
            ViewData["data"] = new SortService().GetList();
            return View();
        }
        public ActionResult GoodDetail(int gid)
        {
            ViewData["data"] = new GoodService().GetOneGood(gid);
            return View();
        }

        public ActionResult XpGood()
        {
            return View();
        }
        public ActionResult RxGood()
        {
            return View();
        }
        /// <summary>
        /// 加入购物车
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public int AddShopCar(FormCollection form)
        {
            TB_ShopCar entity=new TB_ShopCar();
            entity.Id = 0;
            entity.Gid = Convert.ToInt32(form["gid"]);
            entity.TcId = Convert.ToInt32(form["tcid"]); 
            entity.Count = Convert.ToInt32(form["count"]);
            entity.UserId = UserInfo().Id;
            var id= new ShopCarService().Edit(entity);
            if (form["ope"] == "1")
            {
                new OrderService().AddOrder(id.ToString(), UserInfo().Id);
            }
            return id;
        }

       /// <summary>
       /// 获取分类商品列表
       /// </summary>
       /// <param name="pageCount"></param>
       /// <param name="pageIndex"></param>
       /// <param name="sortId"></param>
       /// <param name="name"></param>
       /// <returns></returns>
        public string GetSortGoodsList(int pageCount,int pageIndex,int sortId,string name)
        {
            return JsonConvert.SerializeObject(new GoodService().GetList(pageCount,pageIndex,name,sortId));
        }

        /// <summary>
        /// 获取新品列表
        /// </summary>
        /// <param name="pageCount"></param>
        /// <param name="pageIndex"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetXpGoodsList(int pageCount, int pageIndex, string name)
        {
            return JsonConvert.SerializeObject(new GoodService().GetXpGood(pageCount, pageIndex, name));
        }

        /// <summary>
        /// 获取新品列表
        /// </summary>
        /// <param name="pageCount"></param>
        /// <param name="pageIndex"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetRxGoodsList(int pageCount, int pageIndex, string name)
        {
            return JsonConvert.SerializeObject(new GoodService().GetRxGood(pageCount, pageIndex, name));
        }
        public string Pjlist(int pageIndex, int pageCount,int gid)
        {
            return JsonConvert.SerializeObject(new EvaluateService().GetGidList(pageIndex, pageCount, gid));
        }
    }
}
